define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            var window_innerheight = window.innerHeight;
            var table_height = window_innerheight-20;
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dingdan/package/index',
                    add_url: 'dingdan/package/add',
                    edit_url: 'dingdan/package/edit',
                    del_url: 'dingdan/package/del',
                    multi_url: '',
                    table: 'package',
                },

                pageSize: Config.pagesize,
                height: table_height
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: "套餐名", operate: false},

                        {field: 'status', title: "状态",formatter: Controller.api.formatter.setStatus, searchList: {'1':"上架", '-1':"下架"}},

                        {field: 'remark', title: "备注", operate: false},

                        {field: 'create_time', title: '创建时间',addclass:'datetimerange w200', operate:'RANGE', formatter: Table.api.formatter.datetime},


                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // 打开方式
            Controller.api.bindevent();
        },
        edit: function () {
            // 打开方式
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                setStatus: function (value, row, index) {
                    if(row.status == 1){
                        var html = '<span class="label label-success">上架</span>';
                    }else{
                        var html = '<span class="label label-danger">下架</span>';
                    }
                    return html;
                }
            }
        }
    };
    return Controller;
});
